#include "StartWindow.h"
#include "UsageWindow.h"
#include "HelpWindow.h"
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>
#include <QMovie>
#include <QLabel>
#include "FunctionSelectWindow.h"

StartWindow::StartWindow(QWidget *parent)
    : QMainWindow(parent),
    btnUsage(new QPushButton(tr("使用说明"), this)),
    btnStart(new QPushButton(tr("开始使用"), this)),
    btnHelp(new QPushButton(tr("更多帮助"), this)),
    backgroundLabel(new QLabel(this)),
    backgroundMovie(new QMovie(":/images/background.gif", QByteArray(), this))  // 初始化背景动图
{
    resize(1024, 768);  // 设置窗口大小，确保一致性
    setWindowTitle(tr("线性代数可视化模拟器"));


    // 设置按钮UI
    setupUi();

    // 连接按钮点击事件
    connect(btnUsage, &QPushButton::clicked, this, &StartWindow::onUsageClicked);
    connect(btnStart, &QPushButton::clicked, this, &StartWindow::onStartClicked);
    connect(btnHelp, &QPushButton::clicked, this, &StartWindow::onHelpClicked);
}

StartWindow::~StartWindow() {
    delete btnUsage;
    delete btnStart;
    delete btnHelp;
    delete backgroundLabel;
    delete backgroundMovie;
}

void StartWindow::setupUi() {
    // 创建一个中央容器，包含按钮
    auto *centralWidget = new QWidget(this);
    auto *layout = new QVBoxLayout(centralWidget);
    layout->setContentsMargins(50, 50, 50, 50);  // 设置四周间距
    layout->setSpacing(20);  // 设置按钮间距
    layout->addStretch();  // 添加空白区域
    layout->addWidget(btnUsage);  // 添加按钮
    layout->addWidget(btnStart);  // 添加按钮
    layout->addWidget(btnHelp);   // 添加按钮
    layout->addStretch();  // 添加空白区域
    centralWidget->setLayout(layout);

    // 设置中央控件
    setCentralWidget(centralWidget);
}

void StartWindow::onStartClicked() {
    auto *selector = new FunctionSelectWindow(); // 打开功能选择窗口
    selector->show();
    this->hide();  //隐藏当前窗口
}
void StartWindow::onUsageClicked() {
    UsageWindow *usage = new UsageWindow(this);//打开使用说明窗口
    usage->show();
}

void StartWindow::onHelpClicked() {
    HelpWindow *help = new HelpWindow(this); // 打开帮助窗口
    help->show();

}

